#include "icq_clients.h"
#include "protocol.h"
#include "main.h"
#include "logger.h"
#include "tlv.h"

capstr capShortCaps   = {0x09, 0x46, 0x00, 0x00, 0x4c, 0x7f, 0x11, 0xd1, 0x82, 0x22, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00}; // CAP_AIM_BUDDYICON

capstr* MatchCap(guchar* buf, int bufsize, const capstr* cap, int capsize)
{
	while (bufsize>0) // search the buffer for a capability
	{
		if (!memcmp(buf, cap, capsize))
		{
			return (capstr*)buf; // give found capability for version info
		}
		else
		{
			buf += 0x10;
			bufsize -= 0x10;
		}
	}
	return 0;
}

capstr* MatchShortCap(guchar *buf, int bufsize, const shortcapstr *cap)
{
	capstr fullCap;

	memcpy(fullCap, capShortCaps, 0x10);
	fullCap[2] = (*cap)[0];
	fullCap[3] = (*cap)[1];

	return MatchCap(buf, bufsize, &fullCap, 0x10);
}

guint32 detectUserClient( CLIENT * c, gchar * szUin, guchar* caps, guint16 wLen )
{
    PACKET_CLIENT_INFO_T  client_info;

    memset( &client_info, 0, sizeof(PACKET_CLIENT_INFO_T) );

    memcpy( &client_info.caps, caps, MIN(wLen, 256) );

    P_SendVersion( c,  NULL, szUin );

	return 0;
}
